package com.psg.util;

import lombok.Data;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 63495
 * @Description: 响应类 //
 * @date 2022/5/6 23:06
 */
@Data
public class Result {


    private Integer code;
    private String message;
    private Map<String,Object> data;

    {
        data = new HashMap<>();
    }

    public static Result success(){
        Result result = new Result();
        result.setCode(200);
        result.setMessage("操作成功");
        return result;
    }

    public static Result success(Object data){
        Result result = new Result();
        result.setCode(200);
        result.setMessage("操作成功！");
        result.data.put(null,data);
        return result;
    }

    public static Result success(String message){
        Result result = new Result();
        result.setCode(200);
        result.setMessage(message);
        return result;
    }

    public static Result success(Object data,String message){
        Result result = new Result();
        result.setCode(200);
        result.setMessage(message);
        result.data.put(null,data);
        return result;
    }

    public static Result error(){
        Result result = new Result();
        result.setCode(500);
        result.setMessage("出错了！");
        return result;
    }

    public static Result error(String message){
        Result result = new Result();
        result.setCode(500);
        result.setMessage(message);
        return result;
    }

    public Result add(String key,Object value){
        this.data.put(key,value);
        return this;
    }




}
